package com.xiaozhen.cmdb.controller;

import com.xiaozhen.cmdb.service.CmdbModelService;
import com.xiaozhen.security.controller.BaseController;
import com.xiaozhen.common.core.domain.AjaxResult;
import com.xiaozhen.common.core.domain.cmdb.CmdbModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/8 17:19
 * @description:
 */
@Api(tags = "Cmdb模型接口")
@RestController
@RequestMapping("cmdbModel")
public class CmdbModelController extends BaseController {


    @Autowired
    private CmdbModelService cmdbModelService;

    @ApiOperation("查询模型列表")
    @GetMapping("/selectCmdbModelList")
    public AjaxResult selectCmdbModelList() {
        List<CmdbModel> modelList = cmdbModelService.selectCmdbModelList();
        return AjaxResult.success(modelList);
    }

    @ApiOperation("添加协议模型信息")
    @PostMapping("/addCmdbModel")
    public AjaxResult addCmdbModel(@Validated @RequestBody CmdbModel cmdbModel) {
        cmdbModel.setCreateBy(getCurrentUserId());
        cmdbModel.setCreateTime(LocalDateTime.now());
        return toAjax(cmdbModelService.insertCmdbModel(cmdbModel));
    }

    @ApiOperation("修改协议模型信息")
    @PutMapping("/updateCmdbModel")
    public AjaxResult updateCmdbModel(@Validated @RequestBody CmdbModel cmdbModel) {
        cmdbModel.setUpdateBy(getCurrentUserId());
        cmdbModel.setUpdateTime(LocalDateTime.now());
        return toAjax(cmdbModelService.updateCmdbModel(cmdbModel));
    }

    @ApiOperation("删除协议模型信息")
    @DeleteMapping("/{modelId}")
    public AjaxResult remove(@PathVariable Long modelId) {
        return toAjax(cmdbModelService.deleteModelById(modelId));
    }


}
